package com.training.java.core.collections.car.post15;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

/**
 * The Main purpose this demo is to observe how HashSet is displaying the
 * values.Observe how HashCode compare the equality of 2 objects with different
 * Object References.Observe how is the output if equals methods and hashCode
 * methods are overridden. HashSet Should not take null. HashSet Should not take
 * duplicate objects.HashSet maintains the objects in the Order how we added to
 * the List.
 * 
 * @author Satya
 * 
 */
public class CarHasSetDemo {

	public static void main(String[] args) {

		Car carBmw = new Car("1234", "BMW", "X5");
		Car carFord = new Car("2345", "Ford", "Focus");
		Car carHonda = new Car("3456", "Honda", "City");
		Car carCity = new Car("3456", "Honda", "City");// duplicate object with
		Car car = new Car(); // different object
		// reference.

		// Creating HashSet
		Set<Car> listOfCars = new LinkedHashSet<Car>();

		// Add Car Objects to the HashSet

		listOfCars.add(carBmw);
		listOfCars.add(carFord);
		listOfCars.add(carHonda);
		listOfCars.add(carCity);// Trying to add duplicate object
		// listOfCars.add(null);//NullPointer exception should raise

		// for each loop to iterate

		for (Car aCar : listOfCars)

		{

			// Print the VinNumber, Make, Model of the Cars
			System.out.println("VinNumber of the car : " + aCar.getVinNumber());
			System.out.println("Make of the car :  " + aCar.getMake());
			System.out.println("Model of the Car :" + aCar.getModel());
			System.out.println("***************************");

		}

	}

}
